<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:ctrl="clr-namespace:Jerry.DroidBuilder.ThemeEditor.Controls"
                    xmlns:ext="clr-namespace:Jerry.DroidBuilder.Extensions"
                    xmlns:loc="clr-namespace:Jerry.DroidBuilder"
                    xmlns:local="clr-namespace:Jerry.DroidBuilder">
  <DrawingBrush x:Key="DrawCanvasBackground"
                TileMode="Tile"
                Viewport="0,0,20,20"
                ViewportUnits="Absolute">
    <DrawingBrush.Drawing>
      <DrawingGroup>
        <GeometryDrawing Brush="#FF333333">
          <GeometryDrawing.Geometry>
            <RectangleGeometry Rect="0,0,20,20" />
          </GeometryDrawing.Geometry>
        </GeometryDrawing>
        <GeometryDrawing Brush="#08FFFFFF">
          <GeometryDrawing.Geometry>
            <RectangleGeometry Rect="0,0,10,10" />
          </GeometryDrawing.Geometry>
        </GeometryDrawing>
        <GeometryDrawing Brush="#08FFFFFF">
          <GeometryDrawing.Geometry>
            <RectangleGeometry Rect="10,10,10,10" />
          </GeometryDrawing.Geometry>
        </GeometryDrawing>
      </DrawingGroup>
    </DrawingBrush.Drawing>
  </DrawingBrush>

  <ControlTemplate x:Key="ScalingViewerControlTemplate" TargetType="{x:Type ScrollViewer}">
    <Grid x:Name="Grid" Background="{TemplateBinding Background}">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>
      <Border Grid.Row="1"
              Grid.Column="1"
              Background="#FF595959"
              BorderBrush="#FF333333"
              BorderThickness="1,1,0,0"
              SnapsToDevicePixels="True" />
      <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                              Grid.Row="0"
                              Grid.Column="0"
                              Margin="{TemplateBinding Padding}"
                              CanContentScroll="{TemplateBinding CanContentScroll}"
                              CanHorizontallyScroll="False"
                              CanVerticallyScroll="False"
                              Content="{TemplateBinding Content}"
                              ContentTemplate="{TemplateBinding ContentTemplate}" />
      <DockPanel Grid.Row="0" Grid.Column="1">
        <Control Height="{TemplateBinding MinHeight}" DockPanel.Dock="Top" />
        <ScrollBar x:Name="PART_VerticalScrollBar"
                   AutomationProperties.AutomationId="VerticalScrollBar"
                   Cursor="Arrow"
                   Maximum="{TemplateBinding ScrollableHeight}"
                   Minimum="0"
                   ViewportSize="{TemplateBinding ViewportHeight}"
                   Value="{Binding Path=VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
      </DockPanel>
      <DockPanel Grid.Row="1" Grid.Column="0">
        <TextBlock Width="{TemplateBinding MinWidth}" Text="{TemplateBinding MinWidth}" />
        <ScrollBar x:Name="PART_HorizontalScrollBar"
                   AutomationProperties.AutomationId="HorizontalScrollBar"
                   Cursor="Arrow"
                   Maximum="{TemplateBinding ScrollableWidth}"
                   Minimum="0"
                   Orientation="Horizontal"
                   ViewportSize="{TemplateBinding ViewportWidth}"
                   Value="{Binding Path=HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
      </DockPanel>
    </Grid>
  </ControlTemplate>

  <DataTemplate DataType="{x:Type local:ThemeEditorViewModel}">
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="5" />
        <RowDefinition Height="120" />
      </Grid.RowDefinitions>
      <GridSplitter Grid.Row="1"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch" />
      <TextBox Grid.Row="2"
               AcceptsReturn="True"
               Text="{Binding LayoutXml, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
               TextWrapping="Wrap"
               VerticalScrollBarVisibility="Visible" />
      <ScrollViewer MinWidth="{Binding Path=ActualWidth, ElementName=ScalingPanel, Mode=Default}"
                    Background="{StaticResource DrawCanvasBackground}"
                    HorizontalScrollBarVisibility="Visible"
                    SnapsToDevicePixels="True"
                    Template="{StaticResource ScalingViewerControlTemplate}"
                    VerticalScrollBarVisibility="Visible">
        <ctrl:LayoutEditor Width="{Binding Path=SelectedValue.Width, ElementName=ScaleSize}"
                           Height="{Binding Path=SelectedValue.Height, ElementName=ScaleSize}"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Background="Black"
                           LayoutInfo="{Binding LayoutInfo}">
          <ctrl:LayoutEditor.LayoutTransform>
            <ScaleTransform CenterX="0.5"
                            CenterY="0.5"
                            ScaleX="{Binding Path=SelectedValue, ElementName=ScaleRate}"
                            ScaleY="{Binding Path=SelectedValue, ElementName=ScaleRate}" />
          </ctrl:LayoutEditor.LayoutTransform>
        </ctrl:LayoutEditor>
      </ScrollViewer>
      <StackPanel x:Name="ScalingPanel"
                  HorizontalAlignment="Left"
                  VerticalAlignment="Bottom"
                  Orientation="Horizontal">
        <ComboBox x:Name="ScaleRate"
                  Width="55"
                  Margin="0,0,2,0"
                  DockPanel.Dock="Left"
                  SelectedIndex="4"
                  SelectedValuePath="Tag">
          <ComboBoxItem Content="800%" Tag="8" />
          <ComboBoxItem Content="400%" Tag="4" />
          <ComboBoxItem Content="200%" Tag="2" />
          <ComboBoxItem Content="150%" Tag="1.5" />
          <ComboBoxItem Content="100%" Tag="1" />
          <ComboBoxItem Content="80%" Tag="0.8" />
          <ComboBoxItem Content="50%" Tag="0.5" />
        </ComboBox>
        <ComboBox x:Name="ScaleSize"
                  Width="70"
                  Margin="0,0,2,0"
                  DockPanel.Dock="Left"
                  SelectedIndex="3">
          <ComboBox.ItemTemplate>
            <DataTemplate>
              <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Path=Width}" />
                <TextBlock Text="x" />
                <TextBlock Text="{Binding Path=Height}" />
              </StackPanel>
            </DataTemplate>
          </ComboBox.ItemTemplate>
          <Size Width="800" Height="480" />
          <Size Width="640" Height="480" />
          <Size Width="480" Height="800" />
          <Size Width="480" Height="640" />
          <Size Width="480" Height="480" />
          <Size Width="400" Height="240" />
          <Size Width="320" Height="320" />
          <Size Width="320" Height="240" />
          <Size Width="240" Height="400" />
          <Size Width="240" Height="320" />
        </ComboBox>
      </StackPanel>
    </Grid>
  </DataTemplate>
</ResourceDictionary>